home *** CD-ROM | disk | FTP | other *** search
- Path: news.tau.ac.il!usenet
- From: "Avi L." <avil@sapiens.com>
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: 680X0 -> PPC translator?
- Date: Tue, 26 Mar 1996 16:36:07 +0200
- Organization: Sapiens Tech.
- Message-ID: <315800D7.1854@sapiens.com>
- References: <3143E4EB.7303@sapiens.com> <volker.0fsu@vb.franken.de> <31499F8E.26A9@netvision.net.il> <volker.0fw1@vb.franken.de>
- NNTP-Posting-Host: honda.sapiens.co.il
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (WinNT; I)
-
- Volker Barthelmann wrote:
- >
- > Jack (avilev@netvision.net.il) wrote:
- > :
- > : oh is that so?! unless you get the address from an outside source, such as allocating it YOU
- > : must produce it, right?! so you have to have it stored somewhere in the program. if you get it
- >
- > No. I can get it from system functions or calculate it. And both possibilities
- > can depend on information that is only available at runtime.
-
- you're a little confused here, you're talking about run-time values while that isn't necessary
- to know when and how a certain memory space is used. you use the pointers as parameters
- replacing the actual run-time addresses. these pointers already exist within the program
- and can therefore be analyzed for any changes made to them and how they're being used.
- if you perform careful analysis of the pointers, and that means following the changes made
- to them by the program, you CAN know in which context they are being used and act
- appropriatly. for example:
-
- call _malloc ; let's say register a1 holds the returned address.
- move a1,xyz(a7) ; store it in some variable, noting the current value of a7.
-
- what i mean is, you use your own value of a7 with an initial value of 0 and follow the
- changes made to it resetting it to 0 on assignments. that way you don't need the actual value
- of a7 for knowning to which variable it refers to. now you know the address of the pointer to
- the allocated block i just malloc()'ed so you can know how it's being used later, eg. code or data.
- and bear in mind that all memory allocation routines call evantually AllocMem() function so you
- have the instruction address of where exactly the memory region was allocated and so you can change
- the size argument for the function if that memory area is later used for self-modifying code.
- also you have to follow any loops which do writes to the area cuz these might be the sections
- that copy code into that area and so you have to make the adjustments so that they loop
- according to the translated code size.
- granted, if you call some other function in a library which allocates memory and
- assigns it to a pointer argument given to it, then it'll fail but then even the dynamic approach
- would fail here since the actual allocation was made in a different module all together and
- cannot therefore be changed. this is one of the exceptions to its capabilities i know, but hey
- it's not perfect yet.
-
- >
- > : from some outside source, such as malloc(), then you don't have it obviously but that being said
- > : doesn't imply it's impossible to figure out in which context the address is being used (ie code
- >
- > Easy??
-
- yes easy, cuz as i said you know where it was allocated and you can change the appropriate
- argument.
-
-
- >
- > : calculated code size, remember that the code is sitting somewhere inside your executable and
- > : therefore its size is known, comparing this value to the values pushed to the stack before the
- > : malloc() call and you would find the exact word address to change.
- >
- > You can't simply change all memory allocations of a certain size, because
- > the program could use other chunks of memory that happen to have the same
- > size.
-
- UUUHHH that's where you're wrong cuz i didn't say change all allocation but only those which are
- later used for code (ie self-modifying code, remember)
-
- > And in many programs You won't find any call to e.g. AllocMem with this
- > size at all, because the program uses its own memory-pool-routines.
- > Etc. etc...
-
- but then again it must have allocated the master pool from which it sub-allocates memory from
- and besides it must pass that allocator the required size, so you can change it if that segment
- is later used for code, you know the size of the copied code after all and if the size passed to
- the function is sufficient for the translated code then you don't have to do anything otherwise
- change it.
- >
- > : > Easy said, but really doing this is a different story. First, You'll have to
- > : > kind of disassemble the program and therefore You have to know what is data
- > : > and what is code, but that's what You want to decide, so...
- > : >
- > : > Also doing this kind of analysis is pretty much impossible on Assembler code.
- > : your mind is too cluttered with the complexity of things, but saying it isn't possible is simply
- > : an unfounded claim.
- >
- > It's not unfounded, but I've thought about some things.
- > There are much simpler similar problems that are AFAIK proven to be
- > undecidable.
-
- care to elaborate on this please.
-
- > You can't simply 'keep track' of it, because there are loops and recursions
- > in a program and if it does some more complicated things it's not possible
- > to determine where e.g. a7 points to at a certain instruction, because this
- > depends on the current iteration/recursion or other factors that can't be
- > known before runtime.
-
- what the hell does recursion have to do with anything, it simply calls the function from within
- itself, so what??? if you follow the changes to a7, then you'll always point to the right address,
- remember that auto-variables don't exist cuz the programs is not running and so all references are
- are register (a7) indirect and so nothing really matters, you use registers not absolute addresses.
-
- > What do You mean by ansi-compliant programs and what does this have to do
- > with it?
- heheheh, i mean programs that use ansi C conventions for calling functions, register usage etc...
-
- > Functions are components of certain high level languages. In machine language
- > there are only addresses. Even if this code was generated by a compiler You
- > have to keep track of any jump addresses to be able to determine the
- > beginning and end of a function and what is code an what is data.
-
- gimme one example where i would fail to translate that. believe me it should fine.
-
- >
- > Volker
- >
- > P.S.: Please don't use more than about 78 characters/line
-
- sorry, i didn't really keep track of how long the lines are, maximize your window.
-
- Avi Lev.
-